import joblib
import pandas as pd
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from xgboost import XGBRegressor, XGBClassifier

data= pd.read_csv('../../data/raw/test2.csv')
data['Age']=pd.cut(data['Age'],bins=[17,25,35,45,60],labels=[0,1,2,3])
data['DistanceFromHome']=pd.cut(data['DistanceFromHome'],bins=[0,3,5,10,15,20,30],labels=[0,1,2,3,4,5])
data['MonthlyIncome']=pd.cut(data['MonthlyIncome'],bins=[1000,2000,5000,8000,10000,15000,20000],labels=[0,1,2,3,4,5])
data['PercentSalaryHike']=pd.qcut(data['PercentSalaryHike'],3,labels=[0,1,2])
data['TotalWorkingYears']=pd.cut(data['TotalWorkingYears'],bins=[-1,1,2,5,10,20,30,40],labels=[0,1,2,3,4,5,6])
data['YearsAtCompany']=pd.cut(data['YearsAtCompany'],bins=[-1,1,2,5,10,20,30,40],labels=[0,1,2,3,4,5,6])
data['YearsInCurrentRole']=pd.cut(data['YearsInCurrentRole'],bins=[-1,1,2,5,10,18],labels=[0,1,2,3,4])
data['YearsSinceLastPromotion']=pd.cut(data['YearsSinceLastPromotion'],bins=[-1,1,2,5,10,18],labels=[0,1,2,3,5])
data['YearsWithCurrManager']=pd.cut(data['YearsWithCurrManager'],bins=[-1,1,3,5,8,12,17],labels=[0,1,2,3,4,5])
categorical_cols = data.select_dtypes(include=['object']).columns #.tolist()

le = LabelEncoder()
for i in categorical_cols:
    data[i]=le.fit_transform(data[i])


# x=data[['OverTime','StockOptionLevel','JobLevel','JobRole','MaritalStatus','TotalWorkingYears','Age','JobInvolvement','YearsWithCurrManager','YearsInCurrentRole','JobSatisfaction','YearsAtCompany','EnvironmentSatisfaction','NumCompaniesWorked','WorkLifeBalance','MonthlyIncome']]

x=data[[
    'OverTime',
    'TotalWorkingYears',
    'StockOptionLevel',
    'Age',
    'YearsAtCompany',
    'MonthlyIncome',
    'JobLevel',
    'JobRole',
    'MaritalStatus',
    'YearsWithCurrManager',
    'YearsInCurrentRole',
    'JobInvolvement',
    'JobSatisfaction',
    'EnvironmentSatisfaction',
    'BusinessTravel',
    'EducationField',
    'Department',
    'NumCompaniesWorked',
    'WorkLifeBalance',
    'DistanceFromHome'
]]
y=data['Attrition']
es=joblib.load('./model06_cut.pkl')
y_pre = es.predict_proba(x)[:,1]
auc = roc_auc_score(y, y_pre)
print(f"AUC Score: {auc:.4f}")